package com.dzsw.thread;


import java.util.concurrent.CompletableFuture;

public class CFutureMain0 {

    public static void main(String[] args) throws Exception {
        CompletableFuture<Integer> cf = CompletableFuture.supplyAsync(() -> {
            int result = 0;
            for (int i = 0; i < 100; i++) {
                result += i * 2;
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            return result;
        });
        cf.thenAccept(result -> System.out.println("Result = " + result));
        cf.exceptionally(ex -> {
           ex.printStackTrace();
           return -1;
        });
        cf.get();
    }
}
